Skip to content

templates: fix initramfs merge to preserve filesystem structure and symlinks (avoid cat)#36

Open
quic-mtharu wants to merge 1 commit intoqualcomm-linux:mainfrom
quic-mtharu:main
Open

templates: fix initramfs merge to preserve filesystem structure and symlinks (avoid cat)#36
quic-mtharu wants to merge 1 commit intoqualcomm-linux:mainfrom
quic-mtharu:main

Conversation

@quic-mtharu
Copy link
Contributor

@quic-mtharu quic-mtharu commented Feb 27, 2026

Summary

This PR updates the initramfs merging logic in the fastboot template to avoid using cat for combining initramfs/firmware archives. Instead, when a firmware archive is present, we extract both archives into a single staging directory and repack them into a unified merged-initramfs.cpio.gz.

Problem

The previous approach concatenated cpio files using cat:

cat initramfs-kerneltest-full-image-qcom-armv8a.cpio \
    initramfs-firmware-rb3gen2-image-qcom-armv8a.cpio \
  > merged-initramfs.cpio
gzip merged-initramfs.cpio

This is a byte-stream concatenation and does not actually merge filesystem trees. When one archive provides symlinks (e.g., /lib -> /usr/lib) and the other provides firmware files, early boot path resolution can break (e.g., /lib/firmware not resolving correctly), causing firmware load failures.

Solution

When firmware_name is provided, we now perform a correct merge:

  1. Create a staging directory (rootfs)
  2. Extract the base ramdisk into it
  3. Extract the firmware archive into the same directory (overlay merge)
  4. Repack into a single newc initramfs archive (merged-initramfs.cpio.gz)

This preserves:

  • directory hierarchy
  • symlinks
  • correct final file placement for early boot firmware loading

Scope / Impact

  • Only affects this initramfs merge step.
  • Improves correctness when firmware is supplied as a separate archive.
  • Maintains the output artifact naming expected by downstream steps (merged-initramfs.cpio.gz).

@quic-mtharu quic-mtharu changed the title lava: add fastboot_fastrpc template to merge firmware archives safely templates: fix initramfs merge to preserve filesystem structure and symlinks (avoid cat) Mar 3, 2026
The current initramfs merge logic concatenates cpio payloads using `cat`.
Stream concatenation does not merge filesystem structure and can break early
boot path/symlink resolution when firmware and symlinks are split across
multiple archives.

Replace the `cat` approach with an extract-into-one-dir + repack workflow when
firmware_name is provided:
  - extract ramdisk into a staging rootfs
  - extract firmware archive into the same staging tree
  - repack as a single newc cpio.gz (preserving symlinks and hierarchy)

If firmware_name is not provided, the template produces the merged output by
renaming the original ramdisk artifact to merged-initramfs.cpio.gz.

This improves reliability of /lib -> /usr/lib and /lib/firmware resolution
during early boot and avoids firmware load failures.

Signed-off-by: Tharun Kumar Merugu <mtharu@qti.qualcomm.com>
Copy link

@quic-ggopal quic-ggopal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants